﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace peonwar
{
    public class Hud : Sprite
    {
        // Qulasse pour dessinent le background, le font de le hud, les barres de vye/cooldeauwn
        public Button[] ButtonUnitList;     // Liste des bouttons de spawn
        public ButtonStep[] ButtonUpgradeList;  // listes des boutons dameliorations
        public Button[] ButtonBaseUpgradeList;  // listes des boutons dameliorations de base

        private Button[] LayerList;
        private Sprite[] PanelUpgradeList;
        private Sprite Minimap;
        private Sprite BankTimer;
        private Sprite WarningP1;
        private Sprite WarningP2;
        private Texture2D MinimapBar;
        private Button KillButton;
        private Button ResearchButton;
        private int delay = 1;
        private int PeonSelected;
        private User UserAssociated; // oneziwo

        public int LayerSelected; // de 1 a 3 en fonction de l'onglet selectionner



        public void LoadContent(ContentManager content, User player)
        {
            this.UserAssociated = player;

            // Bouttons d'uniter
            PeonSelected = 0;
            ButtonUnitList = new Button[]
            {
                new Button(new Vector2(360, 490),GameTexture.TextureButtonUnit[1], 1),
                new Button(new Vector2(420, 490),GameTexture.TextureButtonUnit[2], 2),
                new Button(new Vector2(480, 490),GameTexture.TextureButtonUnit[3], 3),
                new Button(new Vector2(573, 490),GameTexture.TextureButtonUnit[10], 4),
                new Button(new Vector2(633, 490),GameTexture.TextureButtonUnit[10], 5),
                new Button(new Vector2(693, 490),GameTexture.TextureButtonUnit[10], 6),
                new Button(new Vector2(785, 490),GameTexture.TextureButtonUnit[10], 7),
                new Button(new Vector2(845, 490),GameTexture.TextureButtonUnit[10], 8),
                new Button(new Vector2(905, 490),GameTexture.TextureButtonUnit[10], 9),
            };

            // Bouttons upgrade peons
            ButtonUpgradeList = new ButtonStep[]
            {
                new ButtonStep(new Vector2(424, 624),GameTexture.TextureButtonUpgrade[4], 0), // Power
                new ButtonStep(new Vector2(554, 624),GameTexture.TextureButtonUpgrade[4], 1), //Accu
                new ButtonStep(new Vector2(684, 624),GameTexture.TextureButtonUpgrade[4], 2), // Resi
                new ButtonStep(new Vector2(814, 624),GameTexture.TextureButtonUpgrade[4], 3), //Speed
            };

            ButtonBaseUpgradeList = new Button[]
            {
                new Button(new Vector2(50, 650), GameTexture.Base_Upgrade_Cost),
                new Button(new Vector2(150, 650),  GameTexture.Base_Upgrade_Income),
                new Button(new Vector2(250, 650),  GameTexture.Base_Upgrade_Health),
            };

            KillButton = new Button(new Vector2(275, 575), GameTexture.KillButton);
            ResearchButton = new Button(new Vector2(45, 480), GameTexture.ResearchButton);

            LayerList = new Button[]
            {
                new Button(new Vector2(420, 580),GameTexture.LayerSelect, 1), // light
                new Button(new Vector2(635, 580),GameTexture.Layer, 2), // medium
                new Button(new Vector2(848, 580),GameTexture.Layer, 3), // heavy

            };

            PanelUpgradeList = new Sprite[]
            {
                new Sprite(390, 635, GameTexture.TextureButtonUpgrade[0]),
                new Sprite(520, 635, GameTexture.TextureButtonUpgrade[0]),
                new Sprite(650, 635, GameTexture.TextureButtonUpgrade[0]),
                new Sprite(780, 635, GameTexture.TextureButtonUpgrade[0]),
            };

            for (int i = 0; i < 9; i++)
            {
                if (!UserAssociated.AvailableUnits[i])
                    ButtonUnitList[i].Texture = GameTexture.TextureButtonUnit[10];
            }


            Minimap = new Sprite(1120, 665, GameTexture.TextureMinimap[5]);
            WarningP1 = new Sprite(985, 654, GameTexture.TextureMinimap[3]);
            WarningP2 = new Sprite(1255, 654, GameTexture.TextureMinimap[3]);
            MinimapBar = GameTexture.TextureMinimap[4];
            BankTimer = new Sprite(280, 515, GameTexture.BankTimer);

            LayerSelected = 0;
        }

        public void TestButtonUnit(User player, MouseState mouse)
        {
            foreach (Button button1 in ButtonUnitList)
            {
                if (!player.AvailableUnits[button1.UnitType - 1]) // uniter non disponible
                    continue;
                if (button1.IsTouched(mouse))
                {
                    PeonSelected = button1.UnitType;
                }
                if (button1.IsPressed(mouse))
                {
                    if (UserAssociated.Available[button1.UnitType - 1])
                    {
                        if (player.Cooldown >= 100)
                        {
                            Unit peonCreated;
                            switch (button1.UnitType)
                            {
                                case (1):
                                    peonCreated = new UnitLight1(player); break;
                                case (2):
                                    peonCreated = new UnitLight2(player); break;
                                case (3):
                                    peonCreated = new UnitLight3(player); break;
                                case (4):
                                    peonCreated = new UnitMedium1(player); break;
                                case (5):
                                    peonCreated = new UnitMedium2(player); break;
                                case (6):
                                    peonCreated = new UnitMedium3(player); break;
                                case (7):
                                    peonCreated = new UnitHeavy1(player); break;
                                case (8):
                                    peonCreated = new UnitHeavy2(player); break;
                                default:
                                    peonCreated = new UnitHeavy3(player); break;
                            }
                            if (player.Bank >= peonCreated.Cost) // creer le peon
                            {
                                player.SpawnUnit(peonCreated); // Spawn l'unite
                                break;
                            }
                            else
                            {
                                GameSound.noCashSound.Play(); // pas asser de thune
                                break;
                            }
                        }
                        else
                        {
                            GameSound.noCashSound.Play(); // pas asser de cooldown
                            break;
                        }
                    }
                    else // peon bloqué (pas encore debloquer)
                    {
                        if (player.Bank >= UserAssociated.AvailableCost[button1.UnitType - 1] && (player.Level >= (button1.UnitType - 1) / 3))
                        {
                            // achete le peon
                            button1.Texture = GameTexture.TextureButtonUnit[button1.UnitType];

                            User.AdvertList.Add(new Advert(new Vector2(button1.Position.X, button1.Position.Y + 40), GameData.Font_Simple, GameData.GameString[48 + button1.UnitType] + GameData.GameString[103], 1.8f, new Vector2(0, 0), 0f, Color.Green, false, new Vector2(0.8f, 1.0f), true));
                            UserAssociated.Available[button1.UnitType - 1] = true;

                            Tools.BankManage(player, -(UserAssociated.AvailableCost[button1.UnitType - 1]));
                        }
                        else
                            GameSound.noCashSound.Play(); // pas asser de thune
                        break;
                    }
                }
            }
        }

        public void UpdateButtonUnitTextures()
        {
            foreach (Button b in ButtonUnitList)
            {
                if ((UserAssociated.Level >= (b.UnitType - 1) / 3) && !UserAssociated.Available[b.UnitType - 1])
                    b.Texture = GameTexture.TextureButtonUnit[0];
            }
        }

        public void UpdatePanels(User player)
        {
            PanelUpgradeList[0].Texture = GameTexture.TextureButtonUpgrade[player.TechPower[LayerSelected] - 1];
            PanelUpgradeList[1].Texture = GameTexture.TextureButtonUpgrade[player.TechAccuracy[LayerSelected] - 1];
            PanelUpgradeList[2].Texture = GameTexture.TextureButtonUpgrade[player.TechResist[LayerSelected] - 1];
            PanelUpgradeList[3].Texture = GameTexture.TextureButtonUpgrade[player.TechSpeed[LayerSelected] - 1];
        }

        public void TestKillButton(User player, User enemyPlayer, MouseState mouse)
        {
            // Boutton pour kill... 
            if (KillButton.IsPressed(mouse))
            {
                player.Kill(enemyPlayer);
            }
        }

        public bool TestResearchButton(MouseState mouse, bool researchUI)
        {
            // Boutton pour l'affichage de l'UI de
            if (ResearchButton.IsPressed(mouse))
                return !researchUI;
            else
                return researchUI;
        }

        public void TestPowerButton(User player, User enemyPlayer, MouseState mouse, bool researchUI)
        {
            foreach (ButtonTimed BT in player.PowersList)
            {
                if (BT.Available && BT.Countdown.UpdateTimer() && BT.IsPressed(mouse) && !researchUI)
                {
                    //Boutton pour le heal
                    if (BT.buttonID == 2 && player.PeonList.Count > 0)
                    {
                        bool launchheal = false;
                        for (int i = 0; i < player.PeonList.Count; i++)
                        {
                            if (player.PeonList[i].Health < player.PeonList[i].MaxHealth && player.PeonList[i].DeadTime == 0 && player.PeonList[i].UnitType != 10)
                            {
                                launchheal = true;
                                break;
                            }
                        }
                        if (launchheal)
                        {
                            player.LaunchPower(Power.Heal, enemyPlayer, 0);
                            BT.Countdown.RestartTimer();
                        }
                    }
                    // Boutton pour bombardement
                    if (BT.buttonID == 3 && !enemyPlayer.IsLaunchingBomb)
                    {
                        player.LaunchPower(Power.Bombe, enemyPlayer, new Random().Next(1, 101));
                        BT.Countdown.RestartTimer();
                    }
                    // Boutton pour gagner de la tune 
                    if (BT.buttonID == 4)
                    {
                        player.LaunchPower(Power.Cresus, enemyPlayer, 0);
                        BT.Countdown.RestartTimer();
                    }
                    // Boutton pour voler l'energie
                    if (BT.buttonID == 1)
                    {
                        player.LaunchPower(Power.EnergyDrainer, enemyPlayer, 0);
                        BT.Countdown.RestartTimer();
                    }
                    // Boutton pour le SUPER PEON!
                    if (BT.buttonID == 5)
                    {
                        player.LaunchPower(Power.SuperPeon, enemyPlayer, 0);
                        BT.Countdown.RestartTimer();
                    }

                    // Boutton pour le random
                    if (BT.buttonID == 6)
                    {
                        Random rnd = new Random();
                        int pwr = rnd.Next(1, 6);
                        int pwr2 = rnd.Next(1, 5);
                        switch (pwr)
                        {
                            case (1):
                                if (player.PeonList.Count > 0 && player.PeonList[0].damaged && player.PeonList[0].DeadTime == 0)
                                {
                                    player.Power_Heal();
                                    player.PowersList[1].Countdown.RestartTimer();
                                }
                                else switch (pwr2)
                                    {
                                        case (1):
                                            player.LaunchPower(Power.Cresus, enemyPlayer, 0); player.PowersList[3].Countdown.RestartTimer(); break;
                                        case (2):
                                            player.LaunchPower(Power.EnergyDrainer, enemyPlayer, 0); player.PowersList[0].Countdown.RestartTimer(); break;
                                        case (3):
                                            player.LaunchPower(Power.SuperPeon, enemyPlayer, 0); ; player.PowersList[4].Countdown.RestartTimer(); break;
                                        case (4):
                                            player.LaunchPower(Power.Bombe, enemyPlayer, new Random().Next(1, 101)); player.PowersList[2].Countdown.RestartTimer();
                                            break;

                                        default:
                                            break;
                                    }
                                break;
                            case (2):
                                player.LaunchPower(Power.EnergyDrainer, enemyPlayer, 0); player.PowersList[0].Countdown.RestartTimer(); break;
                            case (3):
                                player.LaunchPower(Power.Cresus, enemyPlayer, 0); player.PowersList[3].Countdown.RestartTimer(); break;
                            case (4):
                                player.LaunchPower(Power.Bombe, enemyPlayer, new Random().Next(1, 101)); player.PowersList[2].Countdown.RestartTimer();
                                break;
                            case (5):
                                player.LaunchPower(Power.SuperPeon, enemyPlayer, 0); player.PowersList[4].Countdown.RestartTimer(); break;
                            default:
                                break;
                        }
                        BT.Countdown.RestartTimer();
                    }
                }
            }
        }

        public void TestButtonUpgrade(User player, MouseState mouse)
        {
            // Bouttons d'onglet
            foreach (Button button2 in LayerList)
            {
                if (button2.IsPressed(mouse))
                {
                    if (button2.UnitType - 1 != LayerSelected)
                    {
                        LayerList[0].Texture = GameTexture.Layer;
                        LayerList[1].Texture = GameTexture.Layer;
                        LayerList[2].Texture = GameTexture.Layer;
                        LayerList[button2.UnitType - 1].Texture = GameTexture.LayerSelect;
                        LayerSelected = button2.UnitType - 1;
                        UpdatePanels(player);
                    }
                    break;
                }
            }

            // Bouttons ameliorations de la base
            if (ButtonBaseUpgradeList[0].IsPressed(mouse))
                if (player.Bank >= player.ProductionLevel * player.ProductionLevel * (player.character == Perso.Frohman ? 100 : 200)) // tres exponentiel, au carre see you (FU bitch, c'etait une expression pour dire que ca augmentait tres vite! -_-)
                    player.UpgradeProductionLevel();
            if (ButtonBaseUpgradeList[1].IsPressed(mouse))
                if (player.Bank >= player.IncomeLevel * 150)
                    player.UpgradeIncome();
            if (ButtonBaseUpgradeList[2].IsPressed(mouse))
                if (player.Bank >= player.BaseHealthLevel * player.BaseHealthLevel * (player.character == Perso.Frohman ? 50 : 100))
                    player.UpgradeBaseArmor();

            // Bouttons ameliorations des unitées
            for (int i = 0; i < ButtonUpgradeList.Count(); i++)
            {
                ButtonStep button3 = ButtonUpgradeList[i];
                if (UserAssociated.CanUpGrade[LayerSelected, i] && button3.IsPressed(mouse))
                {
                    if (player.Bank >= UserAssociated.Cost[LayerSelected, button3.SkillUpGrade])
                    {
                        if (button3.Press(player, LayerSelected))
                            UserAssociated.CanUpGrade[LayerSelected, i] = false; // Supprime le boutton
                        UpdatePanels(player);
                        GameSound.baseUpSound.Play();
                    }
                    break;
                }
            }
        }

        public void Draw(SpriteBatch spriteBatch, Camera camera, User blue, User red, User enemy)
        {
            // Fond metallic du hud
            spriteBatch.Draw(GameTexture.Backhud, new Rectangle(0, 420, 1280, GameTexture.Backhud.Height), Color.White);

            // Bouttons
            foreach (Button button1 in ButtonUnitList)
            {
                if (UserAssociated.AvailableUnits[button1.UnitType - 1])
                    button1.Draw(spriteBatch);
            }
            for (int i = 0; i < ButtonUpgradeList.Length; i++)
            {
                Button button2 = ButtonUpgradeList[i];
                if (UserAssociated.CanUpGrade[LayerSelected, i])
                {
                    button2.Draw(spriteBatch);
                    int initialCost = UserAssociated.Cost[LayerSelected, i];
                    int finaleCost = initialCost;
                    if (UserAssociated.amlBonus)
                        finaleCost -= (int)(initialCost * 25 / 100);
                    if (UserAssociated.character == Perso.Rengar)
                        finaleCost -= (int)(initialCost * 10 / 100);
                    spriteBatch.DrawString(GameData.Font_Simple, Convert.ToString((int)finaleCost) + " $", new Vector2(button2.Position.X - 15, button2.Position.Y + 40), Color.Maroon);
                }
            }
            foreach (Button button3 in LayerList)
                button3.Draw(spriteBatch);
            foreach (Sprite sprite in PanelUpgradeList)
                sprite.Draw(spriteBatch, null);
            KillButton.Draw(spriteBatch);
            ResearchButton.Draw(spriteBatch);
            int index = 0;
            foreach (Button button4 in ButtonBaseUpgradeList)
            {
                button4.Draw(spriteBatch);
                switch (index)
                {
                    case 0:
                        spriteBatch.DrawString(GameData.Font_Simple, Convert.ToString(UserAssociated.ProductionLevel * UserAssociated.ProductionLevel * (UserAssociated.character == Perso.Frohman ? 100 : 200)), new Vector2(button4.Position.X, button4.Position.Y + 5), Color.WhiteSmoke);
                        break;
                    case 1:
                        spriteBatch.DrawString(GameData.Font_Simple, Convert.ToString(UserAssociated.IncomeLevel * 150), new Vector2(button4.Position.X, button4.Position.Y + 5), Color.WhiteSmoke);
                        break;
                    case 2:
                        spriteBatch.DrawString(GameData.Font_Simple, Convert.ToString(UserAssociated.BaseHealthLevel * UserAssociated.BaseHealthLevel * (UserAssociated.character == Perso.Frohman ? 50 : 100)), new Vector2(button4.Position.X, button4.Position.Y + 5), Color.WhiteSmoke);
                        break;
                }
                index++;
            }
            for (int butt = 0; butt < Game.p1_player.PowersList.Length; butt++)//LooooOOOooooL
            {
                ButtonTimed button5 = Game.p1_player.PowersList[butt];
                button5.Draw(spriteBatch);
                if (!button5.Available)
                    spriteBatch.Draw(GameTexture.UILockPower, new Rectangle((int)button5.Position.X - 20, 0, GameTexture.UILockPower.Width, GameTexture.UILockPower.Height), Color.White);
                spriteBatch.DrawString(GameData.Font_Simple, "Lvl " + button5.buttonID, new Vector2(button5.Position.X, button5.Position.Y), UserAssociated.TeamColor);
            }

            // Ameliorations uniter
            spriteBatch.DrawString(GameData.Font_Pause, Convert.ToString(UserAssociated.TechPower[LayerSelected]), new Vector2(420, 639), Color.Black);
            spriteBatch.DrawString(GameData.Font_Pause, Convert.ToString(UserAssociated.TechAccuracy[LayerSelected]), new Vector2(550, 639), Color.Black);
            spriteBatch.DrawString(GameData.Font_Pause, Convert.ToString(UserAssociated.TechResist[LayerSelected]), new Vector2(680, 639), Color.Black);
            spriteBatch.DrawString(GameData.Font_Pause, Convert.ToString(UserAssociated.TechSpeed[LayerSelected]), new Vector2(810, 639), Color.Black);
            // Textes ameliorations
            spriteBatch.DrawString(GameData.Font_Simple, GameData.GameString[24], new Vector2(350, 660), Color.Red);
            spriteBatch.DrawString(GameData.Font_Simple, GameData.GameString[25], new Vector2(473, 660), Color.OrangeRed);
            spriteBatch.DrawString(GameData.Font_Simple, GameData.GameString[26], new Vector2(600, 660), Color.DarkGreen);
            spriteBatch.DrawString(GameData.Font_Simple, GameData.GameString[27], new Vector2(740, 660), Color.Gold);

            // Ornement bank
            Texture2D texture1 = GameTexture.Bankbar;
            spriteBatch.Draw(texture1, new Rectangle(80, 440, texture1.Width, texture1.Height), Color.White);

            // Bank
            spriteBatch.DrawString(GameData.Font_Simple, GameData.GameString[0] + UserAssociated.Bank, new Vector2(109, 452), Color.SandyBrown);

            // Ornement Income
            spriteBatch.Draw(texture1, new Rectangle(80, 490, texture1.Width, texture1.Height), Color.White);

            // Income
            BankTimer.Draw(spriteBatch, null);
            spriteBatch.DrawString(GameData.Font_Pause, Convert.ToString(UserAssociated.chrono.Duration - UserAssociated.chrono.ElapsedTime), new Vector2(271, 502), Color.Black);
            spriteBatch.DrawString(GameData.Font_Simple, GameData.GameString[48] + "   " + (UserAssociated.Income == 0 ? UserAssociated.IncomeLevel * 100 + UserAssociated.IncomeBonus : UserAssociated.Income).ToString() + " $", new Vector2(110, 502), Color.SandyBrown);

            // Ornement barre de cooldown
            Texture2D texture2 = GameTexture.Cooldownbar;
            spriteBatch.Draw(texture2, new Rectangle(-25, 510, texture2.Width, texture2.Height), Color.White);

            // Barre de cooldown
            spriteBatch.Draw(GameTexture.Cooldown, new Rectangle(82, 554, (int)(UserAssociated.Cooldown * 1.39), 22), Color.White);

            // Ornement barre de vie
            Texture2D texture3 = GameTexture.BaseHealthBar;
            spriteBatch.Draw(texture3, new Rectangle(20, 20, texture3.Width, texture3.Height), Color.White);

            // Barre de vie BLEU
            spriteBatch.DrawString(GameData.Font_Simple, blue.Name, new Vector2(25, 50), Color.Blue);
            spriteBatch.DrawString(GameData.Font_Simple, Tools.GetCharacterName(blue.character), new Vector2(25, 70), Color.Blue);
            spriteBatch.Draw(GameTexture.BaseHealth, new Rectangle(128 - (int)((blue.BaseHealth * 100) / (blue.MaxBaseHealth) * 1.06), 37, (int)((blue.BaseHealth * 100) / (blue.MaxBaseHealth) * 1.06) - 1, 11), Color.White);
            if (blue.BaseHealth > 0)
                spriteBatch.DrawString(GameData.Font_Simple, Convert.ToString(blue.BaseHealth), new Vector2(40, 10), Color.Cyan);

            // Ornement barre d'experience
            Texture2D textureE = GameTexture.ExperienceBar;
            spriteBatch.Draw(textureE, new Rectangle(329, 429, 602, 12), Color.White);

            // Barre d'experience
            spriteBatch.Draw(GameTexture.Experience, new Rectangle(330, 430, (int)(UserAssociated.Experience * 0.06) - 1, 10), UserAssociated.TeamColor);
            if (UserAssociated.Level < 6 || UserAssociated.Experience < 10000)
                spriteBatch.DrawString(GameData.Font_Simple, Convert.ToString(UserAssociated.Experience / 10), new Vector2((float)(315 + (UserAssociated.Experience * 0.06)), 440), UserAssociated.TeamColor);
            spriteBatch.DrawString(GameData.Font_Begin, "" + UserAssociated.Level, new Vector2(265, 425), UserAssociated.TeamColor);


            // Ornement barre de vie Enemie
            Texture2D texture4 = GameTexture.BaseHealthBarEnemy;
            spriteBatch.Draw(texture4, new Rectangle(1120, 22, texture4.Width, texture4.Height), Color.White);

            // Barre de vie RED
            string namered = Tools.GetCharacterName(red.character);
            spriteBatch.DrawString(GameData.Font_Simple, red.Name, new Vector2(1250 - (GameData.Font_Simple.MeasureString(red.Name).X), 50), Color.Red);
            spriteBatch.DrawString(GameData.Font_Simple, namered, new Vector2(1250 - (GameData.Font_Simple.MeasureString(namered).X), 70), Color.Red);
            spriteBatch.Draw(GameTexture.BaseHealthEnemy, new Rectangle(1157, 37, (int)((red.BaseHealth * 100) / (red.MaxBaseHealth) * 0.98) - 1, 11), Color.Red);
            if (red.BaseHealth > 0)
                spriteBatch.DrawString(GameData.Font_Simple, Convert.ToString(red.BaseHealth), new Vector2(1200, 10), new Color(1f, 0.4f, 0f));

            // Minimap
            Minimap.Draw(spriteBatch, null);
            if (delay <= 60)
                delay++;
            else
                delay = 1;
            if (delay > 30 && UserAssociated.Attacked)
                WarningP1.Draw(spriteBatch, null);
            if (delay > 30 && enemy.Attacked)
                WarningP2.Draw(spriteBatch, null);
            // Buffer
            foreach (Sprite s in UserAssociated.PeonBufferDisplay)
            {
                s.Draw(spriteBatch, null);
            }


            int x1 = (((camera.Position) * 317) / Game.CurrentMap.Length) + 962;
            int x2 = (((camera.Position + camera.ViewWidth) * 317) / Game.CurrentMap.Length) + 962;
            spriteBatch.Draw(MinimapBar, new Rectangle(x1 + 2, 645, MinimapBar.Width, MinimapBar.Height), Color.White);
            spriteBatch.Draw(MinimapBar, new Rectangle(x2 - 2, 645, MinimapBar.Width, MinimapBar.Height), Color.White);


            spriteBatch.DrawString(GameData.Font_Simple, GameData.GameString[18], new Vector2(368, 572), Color.Gray);
            spriteBatch.DrawString(GameData.Font_Simple, GameData.GameString[19], new Vector2(584, 572), Color.Gray);
            spriteBatch.DrawString(GameData.Font_Simple, GameData.GameString[20], new Vector2(797, 572), Color.Gray);


            if (PeonSelected != 0)
            {
                Texture2D t;
                if (UserAssociated.Available[PeonSelected - 1])
                {
                    t = GameTexture.TextureButtonUnit[PeonSelected];
                    int powR = (int)(UserAssociated.UnitPower[PeonSelected - 1]);
                    int acc = (int)(UserAssociated.UnitAccuracy[PeonSelected - 1] / UserAssociated.TechAccuracy[(PeonSelected - 1) / 3]);
                    int r = (int)(UserAssociated.UnitResist[(PeonSelected - 1) / 3]);

                    string atkType;
                    switch (UserAssociated.UnitAtkType[PeonSelected - 1])
                    {
                        case DamageType.Sliced:
                            atkType = GameData.GameString[76];
                            break;
                        case DamageType.Projectile:
                            atkType = GameData.GameString[77];
                            break;
                        case DamageType.Explosif:
                            atkType = GameData.GameString[78];
                            break;
                        default:
                            atkType = GameData.GameString[79];
                            break;
                    }

                    spriteBatch.DrawString(GameData.Font_Pause, GameData.GameString[48 + PeonSelected], new Vector2(970, 440), Color.Orange);
                    spriteBatch.DrawString(GameData.Font_Simple, GameData.GameString[46] + " : " + UserAssociated.UnitCost[PeonSelected - 1] + " $", new Vector2(970, 460), Color.Maroon);
                    spriteBatch.DrawString(GameData.Font_Simple, GameData.GameString[47] + " : " + UserAssociated.Energy[PeonSelected - 1], new Vector2(1055, 460), Color.Maroon);
                    spriteBatch.DrawString(GameData.Font_Simple, atkType, new Vector2(1145, 460), Color.Maroon);


                    spriteBatch.DrawString(GameData.Font_Simple, GameData.GameString[24] + " : " + (powR * Math.Abs(UserAssociated.UnitTick[PeonSelected - 1])), new Vector2(970, 492), Color.Red);
                    spriteBatch.DrawString(GameData.Font_Simple, GameData.GameString[75] + " : " + (UserAssociated.UnitMaxHealth[PeonSelected - 1]), new Vector2(970, 514), Color.Pink);
                    spriteBatch.DrawString(GameData.Font_Simple, GameData.GameString[25] + " : " + (int)((powR - acc) * 100 / powR) + "%", new Vector2(1110, 492), Color.OrangeRed);

                    spriteBatch.DrawString(GameData.Font_Simple, GameData.GameString[27] + " : " + (int)(UserAssociated.UnitSpeed[PeonSelected - 1] * 100), new Vector2(970, 536), Color.Gold);

                    spriteBatch.DrawString(GameData.Font_Simple, GameData.GameString[30] + " : " + (UserAssociated.UnitprojeResist[PeonSelected - 1] + r > 100 ? 100 : UserAssociated.UnitprojeResist[PeonSelected - 1] + r) + "%", new Vector2(1110, 514), Color.DarkGreen);
                    spriteBatch.DrawString(GameData.Font_Simple, GameData.GameString[31] + " : " + (UserAssociated.UnitexploResist[PeonSelected - 1] + r > 100 ? 100 : UserAssociated.UnitexploResist[PeonSelected - 1] + r) + "%", new Vector2(1110, 536), Color.DarkGreen);
                    spriteBatch.DrawString(GameData.Font_Simple, GameData.GameString[32] + " : " + (UserAssociated.UnitsliceResist[PeonSelected - 1] + r > 100 ? 100 : UserAssociated.UnitsliceResist[PeonSelected - 1] + r) + "%", new Vector2(1110, 558), Color.DarkGreen);

                    spriteBatch.DrawString(GameData.Font_Simple, GameData.GameString[39] + " : " + (UserAssociated.UnitRange[PeonSelected - 1]), new Vector2(970, 558), Color.Blue);
                }
                else
                { // unite pas debloquer
                    t = GameTexture.TextureButtonUnit[10];
                    if (Game.p1_player.Level >= 1 && (PeonSelected == 4 || PeonSelected == 5 || PeonSelected == 6))
                        t = GameTexture.TextureButtonUnit[0];
                    if (Game.p1_player.Level >= 2 && (PeonSelected == 7 || PeonSelected == 8 || PeonSelected == 9))
                        t = GameTexture.TextureButtonUnit[0];

                    if (UserAssociated.AvailableUnits[PeonSelected - 1]) // 
                    {
                        spriteBatch.DrawString(GameData.Font_Simple, GameData.GameString[14] + " : " + UserAssociated.AvailableCost[PeonSelected - 1] + " $", new Vector2(970, 460), Color.Maroon);
                        if (UserAssociated.Level < (PeonSelected - 1) / 3)
                            spriteBatch.DrawString(GameData.Font_Simple, "+ Lvl " + (int)((PeonSelected - 1) / 3), new Vector2(1100, 460), Color.Maroon);
                    }
                }
                spriteBatch.Draw(t, new Rectangle(1223, 440, t.Width, t.Height), Color.White);
            }

            switch (LayerSelected)
            {
                case 0:
                    spriteBatch.DrawString(GameData.Font_Simple, GameData.GameString[18], new Vector2(368, 572), Color.Orange);
                    break;
                case 1:
                    spriteBatch.DrawString(GameData.Font_Simple, GameData.GameString[19], new Vector2(584, 572), Color.Orange);
                    break;
                case 2:
                    spriteBatch.DrawString(GameData.Font_Simple, GameData.GameString[20], new Vector2(797, 572), Color.Orange);
                    break;
            }

        }
    }
}
